import { App } from 'vue';

export function initPermission(app: App) {
	const authStore = useAuthStoreHook();

	app.config.globalProperties.$hasPermission = function hasPermission(name: string) {
		const permission = authStore.userInfo.permission || [];
		const role = authStore.userInfo.role || [];
		return role.indexOf('admin') > -1 || permission.indexOf(name) > -1;
	};
	app.config.globalProperties.$hasRole = function hasRole(name: string) {
		const role = authStore.userInfo.role || [];

		return role.indexOf('admin') > -1 || role.indexOf(name) > -1;
	};
	//@ts-ignore
	uni.$hasRole = app.config.globalProperties.$hasRole;
	//@ts-ignore
	uni.$hasPermission = app.config.globalProperties.$hasPermission;
}
